package com.zhiyin.seal.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    /**
     * 通用时间格式：2018-09-30 15:43:30
     */
    public static final SimpleDateFormat COMMON_DATE_FORMATE = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * 日期编码格式
     */
    public static final SimpleDateFormat CODE_DATE_FORMATE = new SimpleDateFormat("yyMMdd");
    /**
     * 时间编码格式
     */
    public static final SimpleDateFormat CODE_DATETIME_FORMATE = new SimpleDateFormat("yyMMddHHmmss");


    public static String getDateCodeString(Date date){
        return CODE_DATE_FORMATE.format(date);
    }

    public static String getDateCodeString(){
        return CODE_DATE_FORMATE.format(new Date());
    }

    /**
     * 字符串转时间
     * @param strDate
     * @return
     */
    public static Date getDateFromString(String strDate){
        try {
            return COMMON_DATE_FORMATE.parse(strDate);
        } catch (Exception ex){

        }

        return null;
    }

    /**
     * 获取某个月的天数
     * @param date
     * @return
     */
    public static int getDaysOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }
}
